<?php
require_once('../includes/init.php');
$domain = "https://www.pentalink.com";
?>
<?php
$sql = "SELECT count(*) FROM `cart` WHERE `session_id`='".$_SESSION[SESSION_PREFIX]['session_id']."';";
$cart_sum = $db->getOne($sql);

$id = isset($_GET['id'])?(int)$_GET['id']:1;
//处理文章信息
$sql = "SELECT * FROM `article` WHERE `article_id`='".$id."';";	
$news = $db->getRow($sql, true);

$sql = "SELECT * FROM `article` WHERE `article_id`>'".$id." order by article_id asc limit 1';";	
$nextNews = $db->getRow($sql, true);


$sql = "SELECT * FROM `article` WHERE `article_id`<'".$id." order by article_id desc limit 1';";	
$lastNews = $db->getAll($sql, true);

if ($lastNews){
    $lastNews = $lastNews[count($lastNews) - 1];
}

//点击加1
$sql = "UPDATE `article` SET `click_count`=`click_count`+1 WHERE `article_id`='".$id."';";
$db->query($sql);

$sql = "SELECT * FROM `article` order by click_count desc limit 5";
$hotNews = $db->getAll($sql);
$_GET["from_page"] = "news";
?>
<?php include('./header.php');?>
            <!-- 头部搜索框以及导航栏 -->
            <div class="header_div">
                <?php include('./common/search.php');?>
                <?php include('./common/nav.php');?>
            </div>
            
             <!-- 标签 -->
            <div class="post_position">
                <span class="home_span"><a href="./index.php">首页</a> > </span>
                <span><a>行业资讯</a></span>
            </div>

            <div class="news_content">
                <div class="common-layout-left news_detail_content box">
                    <div class="news_detail_info box">
                        <h1><?php echo $news['title'];?></h1>
                        <div class="news_detail_tip">
                            <span>编辑：<?php echo $news['add_man'];?></span>
                            <span class="time"><?php echo $news['update_tm'];?></span>
                            <span class="liulan"><?php echo $news['click_count'];?></span>
                        </div>
                        <div class="news_detail_p_img">
                            <div style="width: 88%;height: 180px;margin: 0 auto 10px;">
                                <img style="cursor: pointer;width: 100%;height: 100%;object-fit: cover;" src="/upload<?php echo $news['pic'];?>" />
                            </div>
                            <?php echo $news['detail'];?>
                        </div>
                        <div class="news_detail_prev_next box">
                            <?php 
                            if($lastNews):
                            ?>
                            <div class="news_detail_prev fl"><a class="ellipsis" href="./newsdetail.php?id=<?php echo $lastNews['article_id']; ?>"><span>上一篇</span><?php echo $lastNews["title"]; ?></a></div>
                            <?php endif;?>
                            <?php 
                            if($nextNews):
                            ?>
                            <div class="news_detail_next fr"><a class="ellipsis" href="./newsdetail.php?id=<?php echo $nextNews['article_id']; ?>"><span>下一篇</span><?php echo $nextNews["title"]; ?></a></div>
                            <?php endif;?>
                        </div>
                    </div>           
                </div>

                <div class="common-layout-right box">
                     
                    <div class="hot_news_block ">
                        <h1 class="box">更多导读</h1>
                        <div class="hot_news_tag box">
                            <ul>

                                <?php
                                if(!empty($hotNews)):
                                foreach($hotNews as $key => $list):
                                ?>
                                    <li>
                                        <a style="display: inherit;" href="/new/newsdetail.php?id=<?php echo $list['article_id'];?>" title="<?php echo $list['title'];?>">
                                            <p class="tit many_line line_two"><?php echo $list['title'];?></p>
                                            <div class="hot_news_tip">
                                                
                                                <span class="time"><?php echo $list['update_tm'];?></span>
                                                <span class="liulan"><?php echo $list['click_count'];?></span>
                                            </div>
                                        </a>
                                    </li>
                                <?php endforeach; ?>
                                <?php endif; ?>

                               
                            </ul>
                        </div>
                    </div>
                    <!-- <div class="hot_news_block ">
                        <h1 class="box">想了解更多？</h1>
                        <div class="knowmany box">
                            <div class="fl_img">
                                <img src="../img/ico_service.png" alt="服务">
                            </div>
                            <div class="fl_info">
                                <h4>请联系五联产品中心:</h1>
                                <h5>075-5266-59921</h2>
                            </div>
                        </div>
                    </div>
                    <div class="hot_news_block ">
                        <h1 class="box">分享到</h1>
                        <div class="news_share box">
                          
                            <div class="news_share_item">
                                <img src="../img/ico_share_qq.png" alt="">
                                <p>QQ好友</p>
                            </div>
                            <div class="news_share_item">
                                <img src="../img/ico_share_wx.png" alt="">
                                <p>微信</p>
                            </div>
                            <div class="news_share_item">
                                <img src="../img/ico_share_wb.png" alt="">
                                <p>新浪微博</p>
                            </div>
                        </div>
                    </div> -->

                </div>
            </div>

<?php include('./footer.php');?>